<%@ page import="Util.Account" %>
<%@ page import="java.util.List" %>
<%@ page import="Util.MysqlOperation" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="Util.Others" %><%--
  Created by IntelliJ IDEA.
  User: 15433
  Date: 2019/7/13
  Time: 11:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>签到</title>
    <link rel="stylesheet" type="text/css" href="js/calendar.css">
</head>
<body >
<%
    Account account=(Account) session.getAttribute("Account");
    if (account==null)
    {
        response.sendRedirect("login.jsp");
        return;
    }
    List<Long> SignInHistory= MysqlOperation.getAllSignInHistory(account);
%>
<div>
    <a href="manage.jsp"><%=account.getName()%></a>
    你好，欢迎来到签到系统 &nbsp;&nbsp;&nbsp;
    <a href="LogoutServlet">注销</a>
</div>
<div class="calendar" style="height: 330px;width: 400px;margin:0 auto;">
    <div class="title">
        <h1 class="green" id="calendar-title">Month</h1>
        <h2 class="green" id="calendar-year">Year</h2>
        <a href="" id="pre"></a>
        <a href="" id="next"></a>
    </div>

    <div class="body">
        <div class="lightgrey body-list">
            <ul>
                <li>SUN</li>
                <li>MON</li>
                <li>TUE</li>
                <li>WED</li>
                <li>THU</li>
                <li>FRI</li>
                <li>SAT</li>

            </ul>

        </div>

        <div class="darkgrey body-list">
            <ul id="days">

            </ul>
        </div>
    </div>
</div>
<%
    if(!MysqlOperation.hasSignInHistory(account,new Date().getTime()))
    {
        %>
        <form action="signin" method="post">
            <input type="submit" value="今日份签到">
        </form>
        <%
    }
%>
<div id="message">
    您已经连续签到了<%=account.getRunningdays()%>天
    <br>
    最多连续签到了<%=account.getMaxrunningdays()%>天
    <br>
    一共签到了<%=MysqlOperation.getSignInHistoryNum(account)%>天
</div>
<div id="history" >
    <table border="1px" style="width: 210px;margin:0 auto;">
        <tr>
            <th colspan="2">历史记录</th>
        </tr>

        <tr>
            <th>日期</th>
            <th>时间</th>
        </tr>
        <%
            for(long ldate:SignInHistory)
            {
                String strdate=new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss").format(new Date(ldate));
                String[] strdates=strdate.split("  ");
                %>
                <tr>
                    <td align="center" valign="middle"><%=strdates[0]%></td>
                    <td align="center" valign="middle"><%=strdates[1]%></td>
                </tr>
                <%
            }
        %>
    </table>


</div>
</body>
<script >
    let  SignInHistory = new Set([0]);
    <%
        for(long ldate:SignInHistory){
            String strdate=new SimpleDateFormat("yyyyMMdd").format(new Date(ldate));
            out.println("SignInHistory.add('"+strdate+"')");
        }
    %>
</script>
<script src="js/calendar.js"></script>
</html>
